Main idea:
I looked at the distribution of historic returns of the S&P. A day negative return of 6% is rather rare, compared to days of -2% or -3%. My strategy will be based on buying those ‘big’ dips as they happen.
And to sell, my algorithm will sell as the big green days come along. Then I will include many rules to this base strategy to maximize profits. Such as:
- What are the cumulative returns over the past x days? Do it for various x’s. Each x with its column.
- What influence does the VIX have?
First lets look at the distributions for the daily, weekly, monthly, trimonthly, semiannual and annual returns of the S&P. It is much better to buy after a 40% drawdown over a certain time than buying a big but insignificant drop in one day.
| stat | 1-day | 126-day | 1260-day | 21-day | 252-day | 5-day | 63-day |
|---|---|---|---|---|---|---|---|
| mean | 0.0004608 | 0.0551591 | 0.6490271 | 0.0091948 | 0.1117287 | 0.0022318 | 0.0273274 |
| sd | 0.0118799 | 0.1103940 | 0.6530962 | 0.0457143 | 0.1680155 | 0.0240396 | 0.0759076 |
| kurtosis | 12.0591569 | 2.5171330 | -0.1894247 | 5.2041266 | 1.0730581 | 6.6321009 | 2.9335933 |
| minimum | -0.1094200 | -0.4544900 | -0.3552500 | -0.3275100 | -0.4735400 | -0.1979300 | -0.4146800 |
| maximum | 0.1452000 | 0.5177100 | 2.4806800 | 0.2518500 | 0.7750400 | 0.1940400 | 0.3993600 |
| IQR | 0.0101900 | 0.1172450 | 0.9674050 | 0.0477900 | 0.1733650 | 0.0242600 | 0.0801400 |
It is in times of great volatility that our algorithm would start buying and selling.
So depending on how high is the volatility, the algorithm will decide how much risk to take on each trade execution. With machine learning, you can optimize how great the positions should be depending on volatility. I want my bot to be more aggressive with the buying and less aggressive with selling during volatility spikes.
But one day returns are too unpredictable to make decisions, for that its better to take a weighted decision with accumulated returns over a certain time horizon.
By filtering returns using longer time horizons, it should yield a smaller sample of outstanding returns, by filtering out days where on the first you earn 10% and on the second -8%, for example. And it also has the ability to identify x-day-long trends and capitalize on them.
As we augment the time horizon, the abnormal returns are more scarce and it is more apparent that positive returns come out after negatives. Therefore the long-time horizon opportunities are the ones in which we should more aggressively buy the dip.
The idea now is to, within the range of the long-term abnormal returns, buy the daily dips. To capitalize on this we will buy the stock when the sign of the returns reverses.
Let put the abnormal returns on the stock chart. To better visualize the buying moments:
Is the standard deviation correct?
The standard deviation used already takes into account all these dips. So it could be considered taking the standard deviation of the future at that time. But history repeats itself and this standard deviation would be valid right before the 2008 crash as well as right before the coronavirus crash. Moreover, it shows that these buying/selling opportunities occur in times of high volatility, with measures such as garch and the VIX index, availably known at the time.
Since the bot only activates in abnormal returns, it will not work in time where the market steadily grows, therefore when we buy, we buy in bigger quantities and when we sell, sell in smaller quantities to that way capture as much growth as possible.
Here for example, we buy whenever outstanding returns turn reverse their sign.
| Date | 63-day | 63-rev |
|---|---|---|
| 2002-07-18 | -0.21661 | 1 |
| 2009-05-29 | 0.26055 | 1 |
| 2020-03-12 | -0.20477 | 1 |
| 2020-06-15 | 0.28770 | 1 |
| Date | 126-day | 126-rev |
|---|---|---|
| 2002-07-23 | -0.28398 | 1 |
| 2009-08-21 | 0.39709 | 1 |
| Date | 252-day | 252-rev |
|---|---|---|
| 2010-03-02 | 0.62603 | 1 |
The strategy will consist in buying when:
Cumulative returns reverse signs meaning buying later after the big drawdown when sign turns negative.
And buying when the bull market returns after market crashes.
The selling rules are to sell a smaller quantity when:
We have at least a position of 2, because we want to hold the stock as much as possible during a bull market.
And when there is abnormal positive returns for a one-year period and a 6-month period.